#include<bits/stdc++.h>

using namespace std;

int main() {
    FILE *fp1, *fp2;
    char ch1, ch2, ch3, ch4, flag = 0;
    if ((fp1 = fopen("input.cpp", "r")) == NULL)  // input.cpp为任意带注释的C程序
    {
        printf("file cannot be opened\n");
        exit(1);
    }
    if ((fp2 = fopen("output.cpp", "w")) == NULL) // ouput.cpp为去掉注释后的程序
    {
        printf("file cannot be writed\n");
        exit(1);
    }
    ch1 = fgetc(fp1);
    ch2 = fgetc(fp1);
    while (!feof(fp1)) {
        if (ch1 == '/')
            if (ch2 == '*' || ch2 == '/') {
                if (ch2 == '*') {
                    ch3 = fgetc(fp1);
                    ch4 = fgetc(fp1);
                    while (!(ch3 == '*' && ch4 == '/') && !feof(fp1)) {
                        ch3 = ch4;
                        ch4 = fgetc(fp1);  //read only not write
                    }
                    ch2 = fgetc(fp1);
                }
                if (ch2 == '/')
                    while ((ch2 = fgetc(fp1)) != 10);  //read only /not write
            } else
                fputc(ch1, fp2);
        else
            fputc(ch1, fp2);
        ch1 = ch2;
        ch2 = fgetc(fp1);

    }
    fputc(ch1, fp2);
    fclose(fp1);
    fclose(fp2);
}
